home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1994 October
/
Macformat17.cdr
/
Shareware City
/
Applications
/
Alpha.5.81 folder
/
xtcls
/
example2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-28
|
2KB
|
103 lines
#include "xtcl.h"
#include <sound.h>
#define STR_LEN 80
/*
* Think C 5.04 - be sure to link w/ an A4-based version of the ANSI library.
* The following routine uses the callback function to create an Alpha menu
* whose items call back into this XTCL...
*
* The Alpha menu contains a list of sounds that can by played back .
*
* This rsrc *must* be loaded into Alpha's resource fork so that it
* can be found when called from the menu. Alpha currently (5.3) *is*
* distributed w/ this resource installed. To try it out, merely go to
* the Tcl shell and type "xtclcmd sounds init".
*/
void
main(argc, argv, xpb)
long argc;
char **argv;
XTCLParmBlk *xpb;
{
char *ptr, *errString;
long i;
Handle sHandle;
if (argc < 2)
{
usage:
errString = "Usage: sounds init\r sounds beep <sound-name>\r sounds beep Remove";
SetHandleSize(xpb->resultH, (long)STR_LEN);
strncpy(*xpb->resultH, errString, (long)STR_LEN);
(*xpb->resultH)[STR_LEN - 1] = 0;
xpb->result = TCL_ERROR;
return;
}
xpb->result = TCL_OK;
sHandle = NewHandle(500);
HLock(sHandle);
if (!strcmp(argv[1], "init"))
{
ResType type;
int i, num;
char *ptr = *sHandle;
strcpy(ptr, "menu -n Sounds -m -p playSound {\r");
num = CountResources('snd ');
for (i = 1; i <= num; i++)
{
Handle rsrc;
short id;
ResType dummyType;
char name[STR_LEN];
rsrc = GetIndResource('snd ', i);
GetResInfo(rsrc, &id, &dummyType, name);
name[name[0] + 1] = 0;
strcat(ptr, "\"");
strcat(ptr, name + 1);
strcat(ptr, "\" ");
ReleaseResource(rsrc);
}
strcat(ptr, "\"(-\" \"Remove\"}\r");
strcat(ptr, "proc playSound {menu name} {xtclcmd Sounds beep \"$name\"}\r");
strcat(ptr, "insertMenu Sounds\r");
(* xpb->eval)(xpb, sHandle, NULL, NULL);
}
else if (!strcmp("beep", argv[1]))
{
Handle snd;
char temp[STR_LEN];
if (argc != 3) goto usage;
if (!strcmp(argv[2], "Remove"))
{
strcpy(*sHandle, "removeMenu Sounds\r");
(* xpb->eval)(xpb, sHandle, NULL, NULL);
}
else
{
strcpy(temp + 1, argv[2]);
temp[0] = strlen(temp + 1);
if (!(snd = GetNamedResource('snd ', temp))) goto usage;
SndPlay((long)NULL, snd, FALSE);
ReleaseResource(snd);
}
}
else
{
HUnlock(sHandle);
DisposHandle(sHandle);
goto usage;
}
HUnlock(sHandle);
DisposHandle(sHandle);
}